home *** CD-ROM | disk | FTP | other *** search
- Path: mail2news.demon.co.uk!genesis.demon.co.uk
- From: Lawrence Kirby <fred@genesis.demon.co.uk>
- Newsgroups: comp.lang.c
- Subject: Re: routine for yesterday's date
- Date: Mon, 01 Apr 96 22:14:31 GMT
- Organization: none
- Message-ID: <828396871snz@genesis.demon.co.uk>
- References: <315c4d0f.19874776@ottnews.shl.com> <1996Mar30.043002.19054@sq.com>
- Reply-To: fred@genesis.demon.co.uk
- X-NNTP-Posting-Host: genesis.demon.co.uk
- X-Newsreader: Demon Internet Simple News v1.27
- X-Mail2News-Path: genesis.demon.co.uk
-
- In article <1996Mar30.043002.19054@sq.com> msb@sq.com "Mark Brader" writes:
-
- >You might think to fix the first problem by adding the line:
- >
- > x.tm_isdst = -1;
- >
- >at the top, effectively forcing mktime() to work by wall clock time.
- >Now you are asking for the same time yesterday, rather than the time 24
- >hours ago. But this doesn't fix the problem -- in the case of a daylight
- >saving time transition, "the same time yesterday" might be ambiguous or
- >not exist. In such a case a failure of mktime() is allowed (or perhaps
- >required, depending on how one interprets the standard).
-
- IMHO mktime() can't fail simply because of this. It it failed because
- 02:30 doesn't exist on a day then it should equally fail for 25:00 which
- doesn't exist on any day. In the case of 02:30 2 hours 30 mins after
- midnight is a valid time that is always representable (if the start and end
- of the day are).
-
- >The correct fix is to let the daylight saving time transition take its
- >effect by leaving tm_isdst alone, but to ask for the time 24 hours before
- >a time near noon today. Even if that time is 11 am or 1 pm, it will still
- >be yesterday. So the final version of the code is:
- >
- > x.tm_day--; /* back 1 day (well, 24 hours) */
- > x.tm_hour = 12; /* from some time between noon and 1 pm */
- >
- > /* and normalize */
- > if (mktime (&x) == (time_t) -1) {
- > fprintf (stderr, "mktime failed!!\n");
- > exit(1);
- > }
-
- I could easily set up timezone information on my system to make the
- daylight saving time transition occur at noon creating the same problem
- as before (if it is a problem). You'd need to try at a second time in the
- day if the first fails, e.g. 8am and 4pm.
-
- ...
-
- >There is a terser version of the "final" code: replace the first two lines by
- >
- > x.tm_hour = -12; /* 12 hours before sometime between
- > * midnight and 1 am this morning */
-
- Would you say this could fail if I set a noon DST changeover time?
-
- --
- -----------------------------------------
- Lawrence Kirby | fred@genesis.demon.co.uk
- Wilts, England | 70734.126@compuserve.com
- -----------------------------------------
-